package v1

import (
	"context"
	"wxpay/internal/dto"
	"wxpay/internal/service"
	wxpay "wxpay/pkg/api/v1"
)

// 退款申请 POST /api/v1/wxpay/refund/apply
func (s *Server) RefundApply(ctx context.Context, request *wxpay.RefundApplyRequest) (*wxpay.RefundApplyResponse, error) {
	refundDto := dto.RefundApplyDTO{
		BrandID:     request.BrandId,
		OutTradeNo:  request.OutTradeNo,
		OutRefundNo: request.OutRefundNo,
		Reason:      request.Reason,
		RefundAmount: dto.RefundAmount{
			Refund: request.Amount,
			// 目前币种只支持人民币
			Currency: "CNY",
		},
		FundsAccount: request.FundsAccount,
	}
	if err := service.NewRefundService(s.d).RefundApply(ctx, &refundDto); err != nil {
		return nil, err
	}
	return &wxpay.RefundApplyResponse{RefundId: refundDto.RefundID}, nil
}
